package practice02;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author Administrator
 * @version V1.0
 * @ProjectName:IntelliJ IDEA
 * @PackageName: practice02
 * @ClassName: EmployeeManager
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2019/12/16 19:32
 * @Copyright 大牛版板所有
 */
public class EmployeeManager {
    static ArrayList<Employee> emplList = new ArrayList<>();

    public static int getIndex(String name){
        int index= -1;
        for (int i = 0; i < emplList.size(); i++) {
            if (emplList.get(i).getName().equals(name)){
                index = i;
                break;
            }
        }
        return index;
    }
    public static void showAllInfo(){
        System.out.println("工号\t姓名\t年龄\t工资");
        for (int i = 0; i < emplList.size(); i++) {
            Employee e = emplList.get(i);
            System.out.println(e.getWorkId()+"\t\t"+e.getName()+"\t"+e.getAge()+"\t\t"+e.getWages());
        }
    }


    public static void main(String[] args) {
        // 添加员工信息
        emplList.add(new Employee("zhangsan",1,18,3000));
        emplList.add(new Employee("lisi",2,25,3500));
        emplList.add(new Employee("wangwu",3,22,3200));
        showAllInfo();

        // 插入员工信息
        int index = getIndex("lisi");
        Employee employee = new Employee("zhaoliu",4,24,3300);
        emplList.add(index,employee);
        System.out.println("\n============================================================");
        showAllInfo();

        // 删除员工信息
        index = getIndex("wangwu");
        emplList.remove(index);
        System.out.println("\n============================================================");
        showAllInfo();

        // 迭代遍历
        Iterator<Employee> iter = emplList.iterator();
        while (iter.hasNext()){
            Employee employee1 = iter.next();
            employee1.work();
        }

        // 判断是否有重复
        Employee employee1 = new Employee("zhaoliu",4,22,3400);
        for (Employee em:emplList) {
            if (em.equals(employee1)){
                System.out.println("存在重复!");
            }
        }
    }
}
